package com.richinfo.controller;

import com.github.pagehelper.PageInfo;
import com.richinfo.annotation.LogPrint;
import com.richinfo.entity.query.AppsTodoQuery;
import com.richinfo.entity.TbAppsTodo;
import com.richinfo.service.TbAppsTodoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 指定应用代办
 *
 * @author william
 * @create 2020-07-13 15:26
 **/
@Api(tags = "指定应用代办")
@Controller
@RequestMapping("/appsTodo")
@Slf4j
public class AppsTodoController {

    @Autowired
    private TbAppsTodoService appsTodoService;

    @GetMapping("/todoLists")
    @ApiOperation(value="指定应用代查询接口", notes="根据应用id和用户id进行代办查询")
    @LogPrint
    @ResponseBody
    public PageInfo<TbAppsTodo> queryAppsTodo( @Validated AppsTodoQuery appsTodoQuery){
        return appsTodoService.query(appsTodoQuery);
    }

    @GetMapping("/todo")
    @ApiOperation(value = "根据用户id跳转代办页面", notes = "根据用户id跳转代办页面")
    @LogPrint
    public String todo(@Validated AppsTodoQuery appsTodoQuery, Model model) {
        if (StringUtils.isBlank(appsTodoQuery.getUserId())) {
            return "error/403";
        }
        model.addAttribute("user", appsTodoQuery);
        return "todo/todo";
    }



}
